<template>
	<view class="container">

		<view class="user-section">
			<image class="bg" mode="aspectFill" src="../../static/userinfo/grzx.png"></image>
			<view class="user-info-box">
				<view style="display: flex;align-items: center;">
				<view class="portrait-box">
					<image class="portrait" :src="userInfo.portrait || '/static/missing-face.png'"></image>
				</view>
				<view class="info-box">
					<text class="username">{{userInfo.nickname || '游客'}}</text>
					<view class="username" style="color: #FFFFFF;font-size: 18rpx;padding-top: 8rpx;">
						积分:&nbsp;&nbsp;100<text
							style="padding-left: 14rpx;padding-right: 14rpx;">|</text>余额:&nbsp;&nbsp;100</view>
				</view>
				</view>
				<view>
					<u-icon label="签到" labelPos="bottom" labelColor="#fff" color="#fff" labelSize="10" size="25" name="calendar"></u-icon>
				</view>
			</view>
		</view>

		<view class="cover-container">


			<!-- 订单 -->
			<view class="order-section">
				<view class="order-item" @click="goPage('wdye')" hover-class="common-hover"
					:hover-stay-time="50">
					<text class="yticon icon-yue"></text>
					<text>我的余额</text>
				</view>
				<view class="order-item" @click="goPage('yyjl')" hover-class="common-hover"
					:hover-stay-time="50">
					<text class="yticon icon-yishouhuo"></text>
					<text>我的预约</text>
				</view>
			
				<view class="order-item" @click="goPage('shop_order')" hover-class="common-hover"
					:hover-stay-time="50">
					<text class="yticon icon-shouye"></text>
					<text>我的订单</text>
				</view>
				<view class="order-item" @click="goPage('wdkq')" hover-class="common-hover"
					:hover-stay-time="50">
					<text class="yticon icon-kaquan"></text>
					<text>我的卡券</text>
				</view>
			</view>
		</view>
		<view>
			<image style="width: 100%;" mode="aspectFit" src="../../static/userinfo/grzx2.png"></image>
		</view>
	</view>
</template>
<script>
	import {
		mapState
	} from 'vuex';
	let startY = 0,
		moveY = 0,
		pageAtTop = true;
	export default {
		data() {
			return {
				coverTransform: 'translateY(0px)',
				coverTransition: '0s',
				moving: false,
			}
		},
		onLoad() {},
		// #ifndef MP
		onNavigationBarButtonTap(e) {
			const index = e.index;
			if (index === 0) {
				this.navTo('/pages/set/set');
			} else if (index === 1) {
				// #ifdef APP-PLUS
				const pages = getCurrentPages();
				const page = pages[pages.length - 1];
				const currentWebview = page.$getAppWebview();
				currentWebview.hideTitleNViewButtonRedDot({
					index
				});
				// #endif
				uni.navigateTo({
					url: '/pages/notice/notice'
				})
			}
		},
		// #endif
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		methods: {
			goPage(url){
				uni.navigateTo({
					url:`./${url}/${url}`
				})
			},
			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navTo(url) {
				if (!this.hasLogin) {
					url = '/pages/public/login';
				}
				uni.navigateTo({
					url
				})
			},

			/**
			 *  会员卡下拉和回弹
			 *  1.关闭bounce避免ios端下拉冲突
			 *  2.由于touchmove事件的缺陷（以前做小程序就遇到，比如20跳到40，h5反而好很多），下拉的时候会有掉帧的感觉
			 *    transition设置0.1秒延迟，让css来过渡这段空窗期
			 *  3.回弹效果可修改曲线值来调整效果，推荐一个好用的bezier生成工具 http://cubic-bezier.com/
			 */
			coverTouchstart(e) {
				if (pageAtTop === false) {
					return;
				}
				this.coverTransition = 'transform .1s linear';
				startY = e.touches[0].clientY;
			},
			coverTouchmove(e) {
				moveY = e.touches[0].clientY;
				let moveDistance = moveY - startY;
				if (moveDistance < 0) {
					this.moving = false;
					return;
				}
				this.moving = true;
				if (moveDistance >= 80 && moveDistance < 100) {
					moveDistance = 80;
				}

				if (moveDistance > 0 && moveDistance <= 80) {
					this.coverTransform = `translateY(${moveDistance}px)`;
				}
			},
			coverTouchend() {
				if (this.moving === false) {
					return;
				}
				this.moving = false;
				this.coverTransition = 'transform 0.3s cubic-bezier(.21,1.93,.53,.64)';
				this.coverTransform = 'translateY(0px)';
			}
		}
	}
</script>
<style lang='scss'>
	%flex-center {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	%section {
		display: flex;
		justify-content: space-around;
		align-content: center;
		background: #fff;
		border-radius: 10upx;
	}

	.mycard {
		width: 722rpx;
		height: 193rpx;
		background: linear-gradient(180deg, #4A4A4A 0%, #000000 100%);
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		margin: 15rpx;
	}

	.user-section {
		height: 422upx;
		padding: 41upx 50upx 0;
		position: relative;

		.bg {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			/*filter: b lur(1px);
			opacity: .7; */
		}
	}

	.user-info-box {
		height: 180upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background: rgba(58,58,58,0.65);
		border-radius: 20px 20px 20px 20px;
		padding: 40rpx 18rpx 40rpx 18rpx;
		position: relative;
		z-index: 1;
		top: 300upx;;
		.portrait {
			width: 130upx;
			height: 130upx;
			border: 5upx solid #fff;
			border-radius: 50%;
		}

		.username {
			font-size: $font-lg + 6upx;
			color: #fff;
			margin-left: 33upx;
		}
	}

	.vip-card-box {
		display: flex;
		flex-direction: column;
		color: #000;
		height: 116upx;
		width: 600rpx;
		background: linear-gradient(133deg, #FFE8CF 0%, #D4A269 98%);
		border-radius: 15rpx 15rpx 15rpx 15rpx;
		/* overflow-x: visible; */
		padding: 20upx 41upx;

		.tit {
			font-size: 20upx;
			display: flex;
			color: #000;

			.yticon {
				color: #f6e5a3;
				margin-right: 16upx;
			}
		}

		.e-b {
			font-size: 18rpx;
			color: #626262;
		}
	}

	.cover-container {
		background: $page-color-base;
		/* margin-top: -150upx; */
		/* padding: 0 30upx; */
		position: relative;
		background: #f5f5f5;
		padding-bottom: 20upx;
		margin-top: 200upx;
		.arc {
			position: absolute;
			left: 0;
			top: -34upx;
			width: 100%;
			height: 36upx;
		}
	}

	.tj-sction {
		@extend %section;
		background: transparent;

		.tj-item {
			@extend %flex-center;
			flex-direction: column;
			height: 140upx;
			font-size: $font-sm;
			color: #75787d;
		}

		.num {
			font-size: 40rpx;
			color: #FDCE9A;
			margin-bottom: 8upx;
		}
	}

	.order-section {
		@extend %section;
		padding: 28upx 0;
		background-color: transparent;
		margin-top: 20upx;

		.order-item {
			@extend %flex-center;
			width: 120upx;
			height: 120upx;
			border-radius: 10upx;
			font-size: $font-sm;
			color: $font-color-dark;
		}

		.yticon {
			font-size: 48upx;
			margin-bottom: 18upx;
			color: #fa436a;
		}

		.icon-shouhoutuikuan {
			font-size: 44upx;
		}
	}

	.history-section {
		padding: 30upx 0 0;
		margin-top: 20upx;
		background: #fff;
		border-radius: 10upx;

		.sec-header {
			display: flex;
			align-items: center;
			font-size: $font-base;
			color: $font-color-dark;
			line-height: 40upx;
			margin-left: 30upx;

			.yticon {
				font-size: 44upx;
				color: #5eba8f;
				margin-right: 16upx;
				line-height: 40upx;
			}
		}

		.h-list {
			white-space: nowrap;
			padding: 30upx 30upx 0;

			image {
				display: inline-block;
				width: 160upx;
				height: 160upx;
				margin-right: 20upx;
				border-radius: 10upx;
			}
		}
	}
</style>